import re

DEFAULT_PAGE_SIZE = 0x1000
FIREFOX_PAGE_SIZE = 0x8000
LEAF_PAGE_FLAG = 0xd

# 当前已知chome内核浏览器均使用的0x1000大小页，火狐0x8000, midori 0x4000
# 暂未检查midori
PAGE_SIZE_LIST = [0x1000, 0x8000]

# cell存在意义，且需要有网址的文本段 2+4+10 cell head, record head, url
MIN_CELL_SIZE = 16

url_parttern = re.compile(r'^http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')


def conver_bytes_to_int(num_bytes: bytes) -> int:
    return int.from_bytes(num_bytes, byteorder='big', signed=False)


def sum_list_last(numlist, lastnum):
    if len(numlist) <= lastnum:
        return sum(numlist)
    tmp = numlist[len(numlist)-lastnum:]
    return sum(tmp)


def compare_list_ignore_NoneType(src, dst):
    if not src or not dst or len(src) != len(dst):
        return False

    for e in src:
        index = src.index(e)
        if e == type(None) or dst[index] == type(None):
            continue
        if e != dst[index]:
            return False

    return True
